package operation;

import book.Book;
import book.BookList;

import java.util.Scanner;

public class AddOperation implements IOperation{
    @Override
    public void work(BookList bookList) {
        Scanner scanner = new Scanner(System.in);
        int i = bookList.getUsedSize();
        System.out.println("新增图书");

        System.out.print("书名：");
        String name = scanner.nextLine();

        System.out.print("作者名：");
        String author = scanner.nextLine();

        System.out.print("类型： ");
        String type = scanner.nextLine();

        System.out.print("价钱： ");
        int price = scanner.nextInt();

        Book book = new Book(name,author,price,type);
        for (int j = 0; j < bookList.getUsedSize(); j++) {
            Book book1 = bookList.getBook(j);
            if (book1.getName().equals(name)){
                System.out.println("书库中已存在此书");
                return;
            }
            if(bookList.getUsedSize()==bookList.getBooks().length){
                System.out.println("书库满了");
            }else {
                bookList.setBook(i,book);
                bookList.setUsedSize(i+1);
                return;
            }

        }

    }
}
